package com.aaa.rent.controller.api;/**
 * Date:2023/3/1
 * Author：臣哥哥
 * Description:
 */

import com.aaa.entity.Brand;
import com.aaa.rent.service.BrandService;
import com.aaa.security.annotation.HasPermission;
import com.aaa.security.annotation.MyLog;
import com.aaa.util.UploadUtil;
import com.aaa.vo.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

/**
 * @author     ：Xiaochen
 * @date       ：Created in 2023/3/1 11:41
 * @description：
 * @modified By：
 * @version:
 */
@Api(value = "/rent/api/brand", tags = {"api品牌控制"})
@RestController
@RequestMapping("/rent/api/brand")
public class ApiBrandController {
    @Autowired
    private BrandService brandService;

    /**
     *头像上传
     * @param file
     * @return
     * @throws Exception
     */
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "form", dataType = "file", name = "file", value = "", required = true)
    })
    @ApiOperation(value = "头像上传", notes = "头像上传")
    @MyLog(title = "头像上传")
    @RequestMapping("/upload")
    @ResponseBody
    public Result upload(MultipartFile file)throws Exception {
        String path = UploadUtil.ossUpload(file);
        return new Result(2000, "添加成功", path);
    }

    /**
     * 模糊分页查询
     * @param currentPage
     * @param pageSize
     * @param brand
     * @return
     */
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", dataType = "int", name = "currentPage", value = "", required = true),
            @ApiImplicitParam(paramType = "query", dataType = "int", name = "pageSize", value = "", required = true),
            @ApiImplicitParam(paramType = "body", dataType = "Brand", name = "brand", value = "", required = true)
    })
    @ApiOperation(value = "模糊分页查询", notes = "模糊分页查询")
    @MyLog(title = "查询所有车辆品牌")
    @RequestMapping("select")
    @ResponseBody
    public Result list(Integer currentPage, Integer pageSize, @RequestBody Brand brand){
        return brandService.selectAll(currentPage,pageSize,brand);
    }

    /**
     * 修改
     * @param brand
     * @return
     */
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "body", dataType = "Brand", name = "brand", value = "", required = true)
    })
    @ApiOperation(value = "修改", notes = "修改", httpMethod = "POST")
    @MyLog(title = "修改车辆品牌")
    @PostMapping("update")
    public Result update(@RequestBody Brand brand){
        return brandService.update(brand);
    }

    /**
     * 删除
     * @param id
     * @return
     */
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", dataType = "int", name = "id", value = "", required = true)
    })
    @ApiOperation(value = "删除", notes = "删除", httpMethod = "GET")
    @MyLog(title = "删除车辆品牌")
    @GetMapping("delete")
    public Result delete(Integer id){
        return brandService.delete(id);
    }

    /**
     * 添加
     * @param brand
     * @return
     */
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "body", dataType = "Brand", name = "brand", value = "", required = true)
    })
    @ApiOperation(value = "添加", notes = "添加", httpMethod = "POST")
    @MyLog(title = "添加车辆品牌")
    @PostMapping("insert")
    public Result insert(@RequestBody Brand brand){
        return brandService.insert(brand);
    }
}